package wili.misc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author weilai
 */
class RowExhausterOnOptsList_test {
    //若无(主管|经理|财务)签字 (P|S|C|F)类产品(现货|预售)不能(高于)库存(0.5|1|5|-1)倍
    public static List<List<Object>> test2(int opt) {
        if (opt < 0)
            return null;

        Object[][] aa = {{"主管", "总经理", "财务"}, {"P", "S", "C", "F"}, {"现货", "预售"}};
        RowExhausterOnOptsList it = new RowExhausterOnOptsList(true, aa);
        List<List<Object>> ret = new ArrayList<>();
        int times = 0;
        while (it.hasNext()) {
            Object[] next = it.next();
            List<Object> lis = new ArrayList<>(Arrays.asList(next));
            double[] nn = {0.5, 1, 5, -1};
            double tim = nn[(int) (nn.length * Math.random())];
            Object c0 = lis.get(0), c2 = lis.get(2);
            if (c0.equals("总经理")) {
                tim *= 2;
            }
            if (c2.equals("预售")) {
                double tim2 = (double) ret.get(ret.size() - 1).get(3);
                if (tim > tim2) {
                    tim2 = tim;
                }
            }
            lis.add(tim);
            ret.add(lis);
            ++times;
            System.out.println(times + ":" + lis);
        } //
        return ret;
    }

    static void test1(int opt) {
        if (opt < 0)
            return;
        List[] aa = {Arrays.asList("joe", "aa", "mike"), Arrays.asList(77, 11, 88, 44)};
        RowExhausterOnOptsList it = new RowExhausterOnOptsList(true, aa);
        for (int i = 0; i < 3; i++) {
            if (i == 1)
                it.setGeneratorAt(0, (ind, row) -> 10 * (Integer) row[1]);
            else if (i == 2) {
                it.setGeneratorAt(0, null);
                it.addAcceptor((ind, arr) -> ((Integer) arr[1]) % 2 != 0);
            }
            System.out.println("-------");
            int times = 0;
            it.reset();
            while (it.hasNext()) {
                Object[] ret = it.next();
                ++times;
                System.out.println(times + ":" + Arrays.asList(ret));
            } //
        }
    }

    public static void main(String[] args) {
        test1(-1);
        test2(1);
    }

}
